package request

import (
	"fox/common"
	"fox/models"
	"reflect"
)

type Permission struct {
	Paging
}

type SavePermission struct {
	Name          string `json:"name" binding:"omitempty,gt=3"`
	Path          string `json:"path" binding:"required"`
	RequestMethod string `json:"requestMethod" binding:"required"`
}

type UpdatePermission struct {
	ID            int64  `json:"id" binding:"required"`
	Name          string `json:"name" binding:"omitempty,gt=3"`
	Path          string `json:"path" binding:"required"`
	RequestMethod string `json:"requestMethod" binding:"required"`
	Status        int    `json:"status" binding:"omitempty,min=-1,max=1"`
}

func ValidatePermissionSortFile(filed string) bool {
	var (
		permission *models.Permission
		ele        reflect.Type
	)

	permission = &models.Permission{}
	ele = reflect.TypeOf(permission).Elem()
	for i := 0; i < ele.NumField(); i++ {
		var tagSetting = common.ParseTagSetting(ele.Field(i).Tag.Get("gorm"), ";")
		if tagSetting["COLUMN"] == filed {
			return true
		}
	}
	return false
}
